package com.itheima.config;

import com.itheima.listener.SysNoticeListener;
import com.itheima.listener.UserNoticeListener;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    @Bean("sysNoticeContainer")
    public SimpleMessageListenerContainer createSysNoticeContainer(ConnectionFactory connectionFactory) {
        SimpleMessageListenerContainer simpleMessageListenerContainer
                = new SimpleMessageListenerContainer(connectionFactory);
        //使用Chanel
        simpleMessageListenerContainer.setExposeListenerChannel(true);
        //设置自己编写的监听器
        simpleMessageListenerContainer.setMessageListener(new SysNoticeListener());
    return  simpleMessageListenerContainer;
    }
    @Bean("userNoticeListener")
    public SimpleMessageListenerContainer createUserNoticeListener(ConnectionFactory connectionFactory) {
        SimpleMessageListenerContainer simpleMessageListenerContainer
                = new SimpleMessageListenerContainer(connectionFactory);
        //使用Chanel
        simpleMessageListenerContainer.setExposeListenerChannel(true);
        //设置自己编写的监听器
        simpleMessageListenerContainer.setMessageListener(new UserNoticeListener());
        return  simpleMessageListenerContainer;
    }

}
